<template>
  <div>
    <video-player
      id="video_auto"
      class="video-js video-player vjs-custom-skin "
      ref="videoPlayer"
      :playsinline="true"
      :options="playerOptions"
      @play="onPlayerPlay($event)"
      @pause="onPlayerPause($event)"
    ></video-player>
  </div>
</template>

<script>
// 视频
import "vue-video-player/src/custom-theme.css";
import "video.js/dist/video-js.css";
import "videojs-flash";
// import default_poster from "../../assets/zidane.jpg";
import { mapActions } from "vuex";

export default {
  name: "myVideoRTMP",
  props: {
    src: {
      type: String,
      default: ""
    }
  },
  data() {
    return {
      playerOptions: {
        sources: [
          {
            type: "rtmp/mp4",
            src: this.src
          }
        ],
        autoplay: true, // 自动播放
        preload: "auto",
        fluid: true, // 按比例缩放适应容器
        muted: true, // 消除所有音频。
        // poster: default_poster, // 封面

        techOrder: ["flash"],
        aspectRatio: "16:9", // 画面比例

        controls: true, // 控制条
        controlBar: {
          timeDivider: true,
          durationDisplay: true,
          remainingTimeDisplay: false,
          fullscreenToggle: true
        },
        // preload: "auto", // 预加载
        // loop: false, // 循环播放
        notSupportedMessage: "此视频暂无法播放，请稍后再试",
        // language: "zh-CN", // 语言
        // playbackRates: [0.7, 1.0, 1.5, 2.0], // 播放速度
        flash: {
          //   hls: { withCredentials: false },
          swf:
            //   "../../assets/video-js.swf" // 引入静态文件swf
            "https://cdnjs.cloudflare.com/ajax/libs/videojs-swf/5.4.2/video-js.swf"
          // "https://cdn.bootcdn.net/ajax/libs/videojs-swf/5.4.1/video-js.swf" // 引入静态文件swf
          //   swf: "https://cdn.bootcss.com/videojs-swf/5.4.2/video-js.swf" // 引入静态文件swf
        }
        // html5: { hls: { withCredentials: false } }
      }
    };
  },
  watch: {
    src: {
      deep: true,
      handler() {
        //console.log("监控视频地址：", this.src);

        this.playerOptions.sources[0].src = this.src;
      }
    }
  },
  mounted() {},
  computed: {
    player() {
      return this.$refs.videoPlayer.player;
    }
  },
  methods: {
    ...mapActions(["closeDetailsLoadVideoGridPages"]),
    // playV1(v) {
    //   console.log("!!!!!!!!!!");
    //   v.play();
    // },
    gobackVideoGridPages() {
      this.closeDetailsLoadVideoGridPages();
    },
    onPlayerPlay() {
      //   console.log("!!!!!!!？？？？");
      //   v.play();
      //   console.log("!!!!!!!!!!");
      //   console.log(document.getElementById("video_auto"));
      //   let video = document.getElementById("video_auto");
      //   video.load();
      //   video.play();
      //   console.log("!!!!!!!？？？？");
      // console.log("player play!", player);
    },
    onPlayerPause() {
      // console.log("player pause!", player);
    }
  }
};
</script>

<style>
.video-js {
  width: 420px;
  height: 238px;
  /* width: 535px;
  height: 301px; */
}
#vjs_video_3.vjs_video_3-dimensions.vjs-fluid {
  padding-top: 50% !important;
  height: 100%;
}
</style>
